﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;

namespace VeryCodes.Controls.Web
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:EllipseTable runat=server></{0}:EllipseTable>")]
    [ParseChildren(false)]
    [PersistChildren(true)]
    [DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    public class EllipseTable : System.Web.UI.WebControls.WebControl
    {
        private string m_Text;
        private string m_Width = "300";
        private string m_Style = "";
        private string m_CssCalss = "";
        private int m_Height = 120;

        /// <summary>
        /// 控件的样式
        /// </summary>
        [Bindable(true),
        Category("Appearance"),
        DefaultValue("")]
        public new string Style
        {
            get
            {
                return m_Style;
            }

            set
            {
                m_Style = value;
            }
        }


        /// <summary>
        /// 控件的样式表样式
        /// </summary>
        [Bindable(true),
        Category("Appearance"),
        DefaultValue("")]
        public new string CssCalss
        {
            get
            {
                return m_CssCalss;
            }

            set
            {
                m_CssCalss = value;
            }
        }

        /// <summary>
        /// 控件中显示的文本
        /// </summary>
        [Bindable(true)]
        [Description("EllipseTable_Text")]
        [Localizable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        public string Text
        {
            get
            {
                return m_Text;
            }

            set
            {
                m_Text = value;
            }
        }

        /// <summary>
        /// 控件的宽度
        /// </summary>
        [Bindable(true),
        Category("Appearance"),
        DefaultValue("")]
        public new string Width
        {
            get
            {
                return m_Width;
            }

            set
            {
                m_Width = value;
            }
        }

        /// <summary>
        /// 控件的高度
        /// </summary>
        [Bindable(true),
       Category("Appearance"),
       DefaultValue("")]
        public new int Height
        {
            get
            {
                return m_Height;
            }

            set
            {
                m_Height = value;
            }
        }

        //重写WebControl的Render方法，采用HtmlTextWriter类型的参数

        protected override void Render(HtmlTextWriter output)
        {
            output.WriteLine("<table width=\"" + m_Width + "\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"" + m_Style + "\" class=\"" + m_CssCalss + "\">");
            output.WriteLine("<tr>");
            output.WriteLine("<td width=\"8\" height=\"8\"><img src=\"images/left_top.png\" alt=\"left-top\" width=\"8\" height=\"8\" /></td>");
            output.WriteLine("<td height=\"8\" background=\"images/line1_top.png\"></td>");
            output.WriteLine("<td width=\"8\" height=\"8\"><img src=\"images/right_top.png\" alt=\"right-top\" width=\"8\" height=\"8\" /></td>");
            output.WriteLine("</tr>");
            output.WriteLine("<tr>");
            output.WriteLine("<td width=\"8\" background=\"images/line2_left.png\"></td>");
            output.WriteLine("<td width=\"100%\" height=\"" + (m_Height - 16) + "\">");
            output.WriteLine(m_Text);
            if (this.Controls.Count > 0)
            {
                foreach (Control ctl in this.Controls)
                {
                    ctl.RenderControl(output);
                }
            }
            output.WriteLine("</td>");
            output.WriteLine("<td width=\"8\" background=\"images/line2_right.png\"></td>");
            output.WriteLine("</tr>");
            output.WriteLine("<tr>");
            output.WriteLine("<td width=\"8\" height=\"8\"><img src=\"images/left_bottom.png\" alt=\"left-bootom\" width=\"8\" height=\"8\" /></td>");
            output.WriteLine("<td height=\"8\" background=\"images/line1_bottom.png\"></td>");
            output.WriteLine("<td width=\"8\" height=\"8\"><img src=\"images/right_bottom.png\" alt=\"right-bottom\" width=\"8\" height=\"8\" /></td>");
            output.WriteLine("</tr>");
            output.WriteLine("</table>");
            output.Write(Text);
        }
    }
}
